package com.zhaozhaonews.user.controller;


import com.zhaozhaonews.model.common.dto.ResponseResult;
import com.zhaozhaonews.model.common.enums.AppHttpCodeEnum;
import com.zhaozhaonews.model.user.dto.LoginDto;
import com.zhaozhaonews.user.service.ApUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author WanJl
 * @version 1.0
 * @title ApUserLoginController
 * @description App用户登录控制器
 * @create 2025/2/14
 */
@RestController
@RequestMapping("/api/v1/login")
@Api(tags = "App用户登录管理")
public class ApUserLoginController {

    @Resource
    private ApUserService apUserService;

    @PostMapping("/login_auth")
    @ApiOperation("APP用户登录")
    public ResponseResult<Map<String,Object>> login(@RequestBody LoginDto loginDto) {
        Map<String, Object> map = apUserService.login(loginDto);
        if (map == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST,"用户不存在");
        }
        if (map.get("用户名或密码错误")!=null){
            return ResponseResult.errorResult(AppHttpCodeEnum.LOGIN_PASSWORD_ERROR,"用户名或密码错误");
        }

        return ResponseResult.okResult(map);
    }

}
